import express from 'express';
const router = express.Router();

import UserController from '@src/controller/AuthController'
import validateGlobal from '@src/middleware/validate';
import Joi from 'joi';
import Paths from '@src/common/Paths';
import { validateCode } from '@src/middleware/validateCode';

router.post(Paths.Auth.Login, validateGlobal(
    Joi.object({
        username: Joi.string().required().messages({
            'any.required': '用户名不能为空'
        }),
        password: Joi.string().required().messages({
            'any.required': '密码不能为空'
        }),
    })
), UserController.login);

router.post(Paths.Auth.Register, validateGlobal(
    Joi.object({
        username: Joi.string().required().messages({
            'any.required': '用户名不能为空'
        }),
        password: Joi.string().required().messages({
            'any.required': '密码不能为空'
        }),
        email: Joi.string().email().required().messages({
            'any.required': '邮箱不能为空',
            'string.email': '邮箱格式不正确'
        }),
        code: Joi.number().required().messages({
            'any.required': '验证码不能为空'
        })
    })
), validateCode, UserController.register);

export default router;
